﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ZhwangTool
{
    public class ExcelData
    {
        public string[,] GetExcelPaste()
        {
            checked
            {
                string[,] result;
                try
                {
                    string text = System.Windows.Forms.Clipboard.GetText();
                    if (string.IsNullOrEmpty(text))
                    {
                        result = null;
                    }
                    else
                    {
                        string[] array = text.Trim().Split(new char[] {
							'\n'
						});
                        string[] array2 = this.mergesame_t(array[0]).Split(new char[] {
							'\t'
						});
                        int num = array.Length;

                        //int num2 = array2.Length;

                        int num2 = 3;


                        string[,] array3 = new string[num, num2];

                        for (int i = 0; i < num; i++)
                        {
                            string[] array4 = this.mergesame_t(array[i]).Split(new char[] {
								'\t'
							});


                            for (int j = 0; j < num2; j++)
                            {
                                if (array4.Length == 2 && j == 2)
                                {

                                    array3[i, j] = "0";

                                }
                                else
                                {
                                    array3[i, j] = array4[j];
                                }

                            }
                        }
                        result = array3;
                    }
                }
                catch (SystemException var_9_D5)
                {
                    result = null;
                }
                return result;
            }
        }

        private string mergesame_t(string str)
        {
            bool flag = false;
            string text = "";
            checked
            {
                for (int i = 0; i < str.Length; i++)
                {
                    char c = str[i];
                    if (c != '\r')
                    {
                        if (c == '\t')
                        {
                            if (flag)
                            {
                                goto IL_55;
                            }
                            flag = true;
                        }
                        else
                        {
                            flag = false;
                        }
                        text += c;
                    }
                IL_55:
                    ;
                }
                char c2 = text[text.Length - 1];
                if (c2 == '\t')
                {
                    text = text.Substring(0, text.Length - 1);
                }
                return text;
            }
        }
    }
}
